﻿using System;
using System.Collections.Generic;
using Assets.Scripts.Net.Data.Model;
using Assets.Scripts.Net.Loader;
using Assets.Scripts.Tool;
using Assets.Scripts.UI.Buttons;
using Assets.Scripts.UI.Panel;
using UnityEngine;
using UnityEngine.UI;
using Random = UnityEngine.Random;


namespace Assets.Scripts.UI.Item
{
    /// <summary>
    /// 答题状态
    /// </summary>
    public enum QueState
    {
        NotDone,//未作
        Done,//已完成
        Doubt,//疑问
        True,//答对
        False,//答错
    }

    /// <summary>
    /// 问题信息
    /// </summary>
    public class QueItem : UIBase<QueItem>
    {
        public Text QueText;
        public Text AnalysisText;//解析
        public Text AccuracyText;//正确率
        public Transform AnsImageContent;//图片答案
        public Transform AnsTextContent;//普通答案
        public Transform AnsContent;//答案的content
        public Transform QueContent;//问题
        public Transform AnalysisContent;//解析的内容
        public Transform Accuracy;//正确率
        public Transform SubContent;
        public Transform SelectContent;
        public Button AnalysisButton;//解析按钮
        public Button DoubtButton;//疑问按钮
        public Button CollectButton;//收藏按钮
        public Image AnalysisImage;//解析图片

        private ToggleGroup imageToggleGroup;
        private ToggleGroup textToggleGroup;
        private PaperGuideItem guideItem;
        private bool isDoubt;//是否标记为疑问

        /// <summary>
        /// 用来记录答案图片的最大的高
        /// </summary>  
        private float imageHeiht = 0f;//图片的宽
        private QueInfo queInfo { get; set; }//问题信息

        private bool isShowAnalysis;//是否显示解析
        
        protected override UIType UIType
        {
            get { return UIType.Item; }
        }

        protected override void InitOnAwake()
        {
            AutoFindComponent(transform, true);
            imageToggleGroup = AnsImageContent.GetComponent<ToggleGroup>();
            textToggleGroup = AnsTextContent.GetComponent<ToggleGroup>();
            DoubtButton.onClick.AddListener(OnDoubtButtonClick);
            CollectButton.onClick.AddListener(OnCollectButtonClick);
            AnalysisButton.onClick.AddListener(OnAnalysisButtonClick);
            //ExamReslutPanel.OnShowPaperDetailInfo += OnShowPaperInfo;           
        }

        private void OnCollectButtonClick()
        {
            if (queInfo.iscollect == 1)//说明已经收藏
            {
                queInfo.iscollect = 0;
                CollectButton.GetComponent<ButtonSprite>().SetNormalSprite();
            }
            else
            {
                queInfo.iscollect = 1;
                CollectButton.GetComponent<ButtonSprite>().SetPressedSprite();
            }
        }

        private void OnDoubtButtonClick()
        {
            if (isDoubt)//已经标记为疑问
            {
                isDoubt = false;
                DoubtButton.GetComponent<ButtonSprite>().SetNormalSprite();
            }
            else
            {
                isDoubt = true;
                DoubtButton.GetComponent<ButtonSprite>().SetPressedSprite();
            }
            OnMarkedValueChanged(isDoubt);
        }

        protected override void InitOnDestroy()
        {
            //ExamReslutPanel.OnShowPaperDetailInfo -= OnShowPaperInfo;
#if TEST
            ExamPanel.OnRandomAnswer -= OnRandomAnswer;
#endif
        }

        /// <summary>
        /// 显示解析信息
        /// </summary>
        //private void OnShowPaperInfo()  
        //{
        //    AnalysisContent.gameObject.SetActive(true);
        //    AnalysisButton.onClick.Invoke();
        //    if (queInfo.doNum == 0)
        //    {
        //        AccuracyText.text += "0%";
        //    }
        //    else
        //    {
        //        float accuracy = (float)queInfo.rightNum / queInfo.doNum;
        //        int percent = (int)(accuracy * 1000);
        //        AccuracyText.text ="正确率："+percent/10.0+ "%";
        //    }
        //}

        /// <summary>
        /// 是否标记为收藏
        /// </summary>
        /// <param name="isOn"></param>
        private void OnCollcetValueChange(bool isOn)
        {
            if (isOn)
            {
                queInfo.iscollect = 1;
            }
            else
            {
                queInfo.iscollect = 0;
            }
        }


        private void OnAnalysisButtonClick()
        {
            if (!isShowAnalysis)//显示解析
            {
                AnalysisText.gameObject.SetActive(true);
                AnalysisContent.gameObject.SetActive(true);
                AnalysisButton.GetComponent<ButtonSprite>().SetPressedSprite();
                isShowAnalysis = true;
            }
            else//隐藏解析
            {
                AnalysisText.gameObject.SetActive(false);
                AnalysisContent.gameObject.SetActive(false);
                AnalysisButton.GetComponent<ButtonSprite>().SetNormalSprite();
                isShowAnalysis = false;
            }   
        }


        /// <summary>
        /// 判断该题目是否已经作答
        /// </summary>
        /// <returns></returns>
        private bool HaveDone()
        {
            bool haveDone = false;
            List<AnsInfo> ansInfos = queInfo.ansdata;
            for (int i = 0; i < ansInfos.Count; i++)
            {
                if (ansInfos[i].ischoose || (!string.IsNullOrEmpty(ansInfos[i].userans)&&(queInfo.quetype==3||queInfo.quetype==4)))
                {
                    haveDone = true;
                    break;
                }
            }
            return haveDone;
        }

        /// <summary>
        /// 是否标记为疑问
        /// </summary>
        /// <param name="isSelected"></param>
        private void OnMarkedValueChanged(bool isSelected)
        {
            if (isSelected)
            {
                queInfo.questate = 2;//疑问
            }
            else
            {
                if (HaveDone())
                {
                    queInfo.questate = 1;//已答
                }
                else
                {
                    queInfo.questate = 0;//未答
                }
            }
            if(guideItem!=null)
                guideItem.SetGuideState(queInfo.questate);           
        }
     

        /// <summary>
        /// 答案值发生改变的时候回调
        /// </summary>
        private void OnAnsValueChanged()
        {
            if (HaveDone())//如果已经作答
            {
                queInfo.isselect = 1;
                if (queInfo.questate==2)
                    return;
                guideItem.SetGuideState(1);//已答
            }
            else
            {
                queInfo.isselect = 0;
                if (queInfo.questate == 2)
                    return;
                guideItem.SetGuideState(0);//未答
            }
        }

        /// <summary>
        /// 简答填空值发生改变的时候调用
        /// </summary>
        /// <param name="isEmpty"></param>
        public void OnAnsValueChanged(bool isEmpty)
        {
            if (isEmpty)
            {
                queInfo.isselect = 0;
                if (queInfo.questate == 2)
                    return;
                guideItem.SetGuideState(0);//未答
            }
            else
            {
                queInfo.isselect = 1;
                if (queInfo.questate == 2)
                    return;
                guideItem.SetGuideState(1);//已答
            }
        }

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="index"></param>
        /// <param name="info"></param>
        /// <param name="item_guide"></param>
        /// <param name="type"></param>
        /// <param name="isCheckScore"></param> 
        public void Init(int index, QueInfo info, PaperGuideItem item_guide, ExamType type, bool isCheckScore, List<AnsInfo> answerlist = null)
        {
#if TEST
            ExamPanel.OnRandomAnswer += OnRandomAnswer;
#endif
            //隐藏收藏按钮,并且将doubleButton位置放原来收藏的位置上
            if (type==ExamType.Exam)
            {
                CollectButton.gameObject.SetActive(false);
                DoubtButton.gameObject.transform.localPosition = CollectButton.transform.localPosition;
            }
            //显示题目的正确率
            //Debug.Log("queInfo.doNum:" + info.doNum);
            //if (info.doNum == 0)
            //{
            //    AccuracyText.text += "0%";
            //}
            //else
            //{
            //    float accuracy = (float)info.rightNum/info.doNum;
            //    int percent = (int)(accuracy * 1000);
            //    AccuracyText.text = "正确率：" + percent / 10.0 + "%";
            //}            
            if (isCheckScore)//如果查询成绩
            {
                Accuracy.gameObject.SetActive(false);//todo 暂时关闭正确率的功能
                DoubtButton.gameObject.SetActive(false);
                CollectButton.gameObject.SetActive(false);
                //AnalysisButton.gameObject.SetActive(!string.IsNullOrEmpty(info.analysis));
                //SelectContent.gameObject.SetActive(!string.IsNullOrEmpty(info.analysis));
                AnalysisContent.gameObject.SetActive(!string.IsNullOrEmpty(info.analysis));
            }
            else
            {
                Accuracy.gameObject.SetActive(false);
                AnalysisButton.gameObject.SetActive(false);
            }
            //问题部分
            queInfo = info;
            guideItem = item_guide;
            AnalysisText.text += queInfo.analysis;
            //添加解析的图片
            AnalysisImage.gameObject.SetActive(!string.IsNullOrEmpty(queInfo.analysisfile));
            if (ExamPanel._Instance != null)
            {
                ExamPanel._Instance.StartCoroutine(WWWLoadManager.Instance().LoadLocalResource(info.analysisfile, ShowImage));
            }
            else
            {
                CollectPanel._Instance.StartCoroutine(WWWLoadManager.Instance().LoadLocalResource(info.analysisfile, ShowImage));
            }
            QueText.text = index + "." + ReplaceSpace(info.content);
            Transform queTsf = null;
            switch (info.restype)
            {
                case 1://图片
                    queTsf = CreateItem(ItemType.QueImageItem);
                    QueImageItem imageItem = queTsf.GetComponent<QueImageItem>();
                    imageItem.Init(info.respath);
                    break;
                case 2://视频
                    queTsf = CreateItem(ItemType.QueVideoItem);
                    QueVideoItem videoItem = queTsf.GetComponent<QueVideoItem>();
                    string videoPath = info.respath.Substring(info.respath.LastIndexOf("/", StringComparison.Ordinal));
                    videoItem.Init(videoPath); 
                    break;
                case 3://声音
                    queTsf = CreateItem(ItemType.QueAudioItem);
                    QueAudioItem audioItem = queTsf.GetComponent<QueAudioItem>();
                    audioItem.Init(info.respath);
                    break;
            }
            if (queTsf != null)
            {
                QueContent.gameObject.SetActive(true);
                queTsf.SetParent(QueContent);
                queTsf.localPosition = Vector3.zero;
                queTsf.localScale = Vector3.one;
            }
            else
            {
                QueContent.gameObject.SetActive(false);
            }
            //答案部分
            if (answerlist!=null)
            {
                if (info.ansdata == null)
                {
                    info.ansdata = answerlist;
                }
            }
            else
            {
                if (info.ansdata == null)
                {
                    info.ansdata = ExamPanel._Instance.GetAnsInfosByQueId(info.id, false);
                }
            }           
            for (int i = 0; i < info.ansdata.Count; i++)
            {
                info.ansdata[i].restype = string.IsNullOrEmpty(info.ansdata[i].respath) ? 0 : 1;
            }
            //Debug.Log("问题的id:"+info.id+ "____答案的个数："+ansInfos.Count);
            if (info.quetype==2)//是非题，不需要随机
            {
                //添加一个另外一个答案
                if (info.ansdata.Count == 1)
                {
                    AnsInfo ansinfo = new AnsInfo();
                    ansinfo.queid = info.ansdata[0].queid;
                    ansinfo.content = info.ansdata[0].content == "正确" ? "错误" : "正确";
                    ansinfo.isright = info.ansdata[0].isright == 1 ? 0 : 1;
                    ansinfo.restype = 0;
                    if (isCheckScore)//如果是查询成绩
                    {
                        if (info.isselect == 1)
                        {
                            ansinfo.ischoose = Convert.ToBoolean(queInfo.isright)
                                ? Convert.ToBoolean(ansinfo.isright)
                                : !Convert.ToBoolean(ansinfo.isright);
                        }
                        else
                        {
                            ansinfo.ischoose = false;
                        }                   
                    }
                    info.ansdata.Add(ansinfo);
                    RamdomTool.Shuffle(info.ansdata);
                }
                SetToggleGroup(true);
                for (int i = 0; i < info.ansdata.Count; i++)
                {
                    InitAnswer(info.ansdata[i], i, (int)info.quetype, this, isCheckScore);
                }
                if (answerlist == null)
                {
                    ExamPanel._Instance.RamdonedAnsInfos.AddRange(info.ansdata);
                }               
            }
            else if (info.quetype == 0 || info.quetype == 1)//单选多选，不需要随机
            {
                RamdomTool.Shuffle(info.ansdata);
                for (int i = 0; i < info.ansdata.Count; i++)
                {
                    InitAnswer(info.ansdata[i], i, (int)info.quetype, this, isCheckScore);
                }
                if (answerlist == null)
                {
                    ExamPanel._Instance.RamdonedAnsInfos.AddRange(info.ansdata);
                } 
            }
            else if (info.quetype == 5 || info.quetype == 6||info.quetype==7)//随机单选多选公式题
            {
                List<AnsInfo> answers = RandomAnsInfos(info.ansdata, (int)info.quetype, answerlist == null);
                for (int i = 0; i < answers.Count; i++)
                {
                    InitAnswer(answers[i], i, (int)info.quetype, this, isCheckScore);
                }
            }
            else if(info.quetype==3||info.quetype==4)//填空、简答
            {
                AnsContent.gameObject.SetActive(false);
                SubContent.gameObject.SetActive(true);
                Transform tsf = CreateItem(ItemType.AnsSubItem);
                tsf.SetParent(SubContent);
                tsf.localPosition=Vector3.zero;
                tsf.localScale=Vector3.one;
                AnsSubItem item = tsf.GetComponent<AnsSubItem>();
                if (info.ansdata.Count > 0)//答案没有传回来
                {
                    item.Init(info.ansdata[0], (int)info.quetype, OnAnsValueChanged, isCheckScore, queInfo);
                }
                if (answerlist == null)
                {
                    ExamPanel._Instance.RamdonedAnsInfos.AddRange(info.ansdata);
                }
            }
        }



        private void ShowImage(byte[] bytes)
        {
            Texture2D texture = new Texture2D((int)AnalysisImage.rectTransform.rect.width, (int)AnalysisImage.rectTransform.rect.height, TextureFormat.ARGB32, false);
            texture.LoadImage(bytes);
            AnalysisImage.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
            AnalysisImage.GetComponent<LayoutElement>().preferredHeight = AnalysisImage.GetComponent<RectTransform>().rect.height + 50;
        }


        /// <summary>
        /// 解决空格自动换行问题
        /// </summary>
        /// <param name="sourceStr"></param>
        /// <returns></returns>
        public static string ReplaceSpace(string sourceStr)
        {
            return sourceStr.Replace(" ", "<color=#00000000>.</color>");
        }

        /// <summary>
        /// 初始化答案信息
        /// </summary>
        /// <param name="info"></param>
        void InitAnswer(AnsInfo info,int index,int queType, QueItem item,bool isCheckScore=false) 
        {
            Transform tsf = null;           
            switch (info.restype)
            {
                case 0://文本
                    AnsImageContent.gameObject.SetActive(false);
                    AnsTextContent.gameObject.SetActive(true);
                    tsf= CreateItem(ItemType.AnsTextItem);
                    tsf.SetParent(AnsTextContent);
                    tsf.localPosition=Vector3.zero;
                    tsf.localScale=Vector3.one;
                    AnsTextItem textItem = tsf.GetComponent<AnsTextItem>();
                    switch (queType)
                    {
                        case 0://单选
                            textItem.Init(info, GetAnswerLabel(index), OnAnsValueChanged, textToggleGroup, isCheckScore);
                            break;
                        case 1://多选
                            textItem.Init(info, GetAnswerLabel(index), OnAnsValueChanged, null, isCheckScore);
                            break;
                        case 2://是非
                            textItem.Init(info, GetAnswerLabel(index), OnAnsValueChanged, textToggleGroup,isCheckScore);
                            break; 
                        case 5://随机单选
                            textItem.Init(info, GetAnswerLabel(index), OnAnsValueChanged, textToggleGroup, isCheckScore);
                            break;
                        case 6://随机多选
                            textItem.Init(info, GetAnswerLabel(index), OnAnsValueChanged, null, isCheckScore);
                            break;
                        case 7://随机单选(公式题)
                            textItem.Init(info, GetAnswerLabel(index), OnAnsValueChanged, textToggleGroup, isCheckScore);
                            break;
                    }
                    break;
                case 1://图片
                    AnsImageContent.gameObject.SetActive(true);
                    AnsTextContent.gameObject.SetActive(false);
                    tsf=CreateItem(ItemType.AnsImageItem);
                    tsf.SetParent(AnsImageContent);
                    tsf.localPosition=Vector3.zero;
                    tsf.localScale=Vector3.one;
                    AnsImageItem imageItem = tsf.GetComponent<AnsImageItem>();
                    switch (queType)
                    {                        
                        case 0://单选
                            imageItem.Init(info, GetAnswerLabel(index), OnAnsValueChanged, imageToggleGroup, isCheckScore,item);
                            break;
                        case 1://多选
                            imageItem.Init(info, GetAnswerLabel(index), OnAnsValueChanged, null, isCheckScore, item);
                            break;
                        case 2://判断
                            imageItem.Init(info, GetAnswerLabel(index), OnAnsValueChanged, imageToggleGroup, isCheckScore, item); 
                            break;
                        case 5://随机单选
                            imageItem.Init(info, GetAnswerLabel(index), OnAnsValueChanged, imageToggleGroup, isCheckScore, item);
                            break;
                        case 6://随机多选
                            imageItem.Init(info, GetAnswerLabel(index), OnAnsValueChanged, null, isCheckScore, item);
                            break;
                        case 7://随机单选（公式题）
                            imageItem.Init(info, GetAnswerLabel(index), OnAnsValueChanged, imageToggleGroup, isCheckScore, item);
                            break;
                    }
                    break;
            }
        }

        /// <summary>
        /// 得到问题的Label
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        string GetAnswerLabel(int i)
        {
            switch (i)
            {
                case 0:
                    return "A";
                case 1:
                    return "B";
                case 2:
                    return "C";
                case 3:
                    return "D";
                case 4:
                    return "E";
                case 5:
                    return "F";
                case 6:
                    return "G";
                case 7:
                    return "H";
                case 8:
                    return "I";
                default:
                    return null;
            } 
        }

        /// <summary>
        /// 随机得到答案
        /// </summary>
        /// <returns></returns>
        private List<AnsInfo> RandomAnsInfos(List<AnsInfo> ansInfos, int queType,bool isAdd)
        {
            List<AnsInfo> answers = new List<AnsInfo>();
            List<AnsInfo> right = new List<AnsInfo>();
            List<AnsInfo> wrong = new List<AnsInfo>();
            int[] rightIndexs, wrongIndexs;
            for (int i = 0; i < ansInfos.Count; i++)
            {
                if (ansInfos[i].isright == 1)
                {
                    right.Add(ansInfos[i]);                    
                }
                else
                {
                    wrong.Add(ansInfos[i]);
                }
            }
            switch (queType)
            {
                case 5: //随机单选
                    SetToggleGroup(true);
//                    Debug.Log("正确答案的个数："+right.Count);
//                    Debug.Log("错误答案的个数:"+wrong.Count);
                    if (wrong.Count >= 2 && right.Count >= 1)
                    {
                        rightIndexs = RamdomTool.GetRandoms(1, 0, right.Count-1);
                        wrongIndexs = RamdomTool.GetRandoms(3, 0, wrong.Count-1);
                        for (int i = 0; i < rightIndexs.Length; i++)
                        {
                            Debug.Log("rightIndex:" + rightIndexs[i]);
                            answers.Add(right[rightIndexs[i]]);                            
                        }
                        for (int i = 0; i < wrongIndexs.Length; i++)
                        {
                            Debug.Log("wrongIndex:" + wrongIndexs[i]);
                            answers.Add(wrong[wrongIndexs[i]]);                           
                        }
                    }
                    else
                    {
//                        Debug.Log("题目的答案有问题:"+wrong.Count+"_"+right.Count);
                    }
                    break;
                case 6: //随机多选
                    SetToggleGroup(false);
                    if (right.Count + wrong.Count >= 4 && right.Count >= 2) //总提数必须超过五个,todo....后面这里修改回来
                    {
                        int rightNum = 0, wrongNum = 0; //正确与错误答案的数量
                        if (right.Count >= 4)
                        {
                            rightNum = Random.Range(2, 5); //不包含4所以加1
                            //Debug.Log("正确答案的数量：" + rightNum);
                        }
                        else
                        {
                            rightNum = Random.Range(2, right.Count + 1); //不包含4所以加1
                            //Debug.Log("正确答案的数量：" + rightNum);
                        }
                        if (right.Count + wrong.Count == 4)
                        {
                            wrongNum = 4 - rightNum;
                        }
                        else
                        {
                            wrongNum = 5 - rightNum;
                        }
                        if (wrongNum > wrong.Count) //错误答案的数量不足
                        {
                            rightNum += wrongNum - wrong.Count; //增加正确答案的数量补足
                            wrongNum -= wrongNum - wrong.Count;
                        }
                        rightIndexs = RamdomTool.GetRandoms(rightNum, 0, right.Count-1);
                        wrongIndexs = RamdomTool.GetRandoms(wrongNum, 0, wrong.Count-1);
                        if (rightIndexs != null)
                        {
                            for (int i = 0; i < rightIndexs.Length; i++)
                            {
                                answers.Add(right[rightIndexs[i]]);
                            } 
                        }
                        if (wrongIndexs != null)
                        {
                            for (int i = 0; i < wrongIndexs.Length; i++)
                            {
                                answers.Add(wrong[wrongIndexs[i]]);
                            } 
                        }     
                    }
                    break;
                case 7:
                     SetToggleGroup(true);
                    //Debug.Log("正确答案的个数："+right.Count);
                    //Debug.Log("错误答案的个数:"+wrong.Count);
                    if (wrong.Count >= 2 && right.Count >= 1)
                    {
                        rightIndexs = RamdomTool.GetRandoms(1, 0, right.Count-1);
                        wrongIndexs = RamdomTool.GetRandoms(3, 0, wrong.Count-1);
                        for (int i = 0; i < rightIndexs.Length; i++)
                        {
                            //Debug.Log("rightIndex:" + rightIndexs[i]);
                            answers.Add(right[rightIndexs[i]]);                            
                        }
                        for (int i = 0; i < wrongIndexs.Length; i++)
                        {
                            //Debug.Log("wrongIndex:" + wrongIndexs[i]);
                            answers.Add(wrong[wrongIndexs[i]]);                           
                        }
                    }
                    else
                    {
                        Debug.Log("题目的答案有问题:"+wrong.Count+"_"+right.Count);
                    }
                    break;
            }
            //启用随机答案
            RamdomTool.Shuffle(answers);
            //记录显示的答案信息
            queInfo.ansdata = answers;
            if(isAdd)
                ExamPanel._Instance.RamdonedAnsInfos.AddRange(answers);           
            return answers;
        }

        /// <summary>
        /// 设置Toggle组
        /// </summary>
        /// <param name="isActive"></param>
        private void SetToggleGroup(bool isActive)
        {
            imageToggleGroup.enabled = isActive;
            textToggleGroup.enabled = isActive;
        }


        /// <summary>
        /// 清空答案的信息
        /// </summary>
        public void Clear()
        {
            AnsContent.gameObject.SetActive(true);
            SubContent.gameObject.SetActive(false);
            CleanTransformChildren(AnsImageContent);
            CleanTransformChildren(AnsTextContent);
            CleanTransformChildren(SubContent);
            CleanTransformChildren(QueContent);
            QueText.text = "";
        }

        public void SetImageContentHeight(float height)
        {
            if (imageHeiht >= height)
            {
                return;
            }
            imageHeiht = height;
            AnsContent.transform.Find("AnsImageContent").GetComponent<GridLayoutGroup>().cellSize=new Vector2(593.3f,height);
        }

#if TEST
        /// <summary>
        /// 自动答题
        /// </summary>
        private void OnRandomAnswer()
        {
            int randomIndex;
            //0:单选 1:多选 2:判断 3：填空 4：简答 5：随机单选 6：随机多选 7：随机公式
            if (queInfo.quetype != 3 || queInfo.quetype != 4)
            {
                randomIndex = Random.Range(0, AnsTextContent.childCount);
                try
                {
                    AnsTextContent.GetChild(randomIndex).GetComponent<AnsTextItem>().Chose();
                }
                catch (Exception e)
                {
                    Debug.Log("randomIndex:" + randomIndex);                    
                }
                
            }
            else
            {
                //填空和选择已经处理
            }            
        }
#endif
    }
}